package com.fuyun.rpc.registry.impl;

import cn.hutool.core.util.StrUtil;
import com.fuyun.rpc.constant.RpcConstant;
import com.fuyun.rpc.factory.SingletonFactory;
import com.fuyun.rpc.registry.ServiceRegistry;
import com.fuyun.rpc.registry.zk.ZkCLient;
import com.fuyun.rpc.util.IpUtils;
import lombok.extern.slf4j.Slf4j;

import java.net.InetSocketAddress;

/**
 * @Author fuyun。
 * @Date 2025/8/22 11:41。
 * @Description: TODO。
 **/

@Slf4j
public class ZkServiceRegistry implements ServiceRegistry {

    private final ZkCLient client;

    public ZkServiceRegistry() {
        client = SingletonFactory.getInstance(ZkCLient.class);
    }

    public ZkServiceRegistry(ZkCLient client) {
        this.client = client;
    }

    @Override
    public void registerService(String serviceName, InetSocketAddress inetSocketAddress) {
        log.info("服务注册， serviceName {}, address {}", serviceName, inetSocketAddress);

        String path = RpcConstant.ZK_RPC_ROOT_PATH + StrUtil.SLASH + serviceName + StrUtil.SLASH + IpUtils.tpIpPort(inetSocketAddress);
        client.createPersistentNode(path);



    }

    @Override
    public void unregisterService(String serviceName) {


    }
}
